package ObjGitRequest

import (
	"arabApi/app/api/requests"
	"arabApi/app/api/requests/CRequest"
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type ObjGitRequest struct {
	ID      int64  `json:"id"`
	Name    string `json:"name,omitempty" valid:"name"`
	Desc    string `json:"desc,omitempty" valid:"desc"`
	JobPath string `json:"JobPath,omitempty" valid:"job_path"`
	JobType string `json:"JobType,omitempty" valid:"job_type"`
	CRequest.Cpage
}

func CheckGitObj(data interface{}, c *gin.Context) string {
	// 自定义验证规则
	rules := govalidator.MapData{
		"name":     []string{"required"},
		"desc":     []string{"required"},
		"job_path": []string{"required"},
		"job_type": []string{"required"},
	}
	// 自定义验证出错时的提示
	messages := govalidator.MapData{
		"name": []string{
			"required:项目名称不能为空",
		},
		"desc": []string{
			"required:项目描述不能为空",
		},
		"job_path": []string{
			"required:项目路径不能为空",
		},
		"job_type": []string{
			"required:项目类型不能为空",
		},
	}

	errs := requests.Validate1(data, rules, messages)
	return requests.GetOneErr(errs)
}
